<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="x-ua-compatible" content="IE=edge">
		<meta name="viewport"
			content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
		<title>Aliplayer Online Settings</title>
		<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js">
		</script>
		<link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.12.1/skins/default/aliplayer-min.css" />
		<script type="text/javascript" charset="utf-8"
			src="https://g.alicdn.com/de/prismplayer/2.12.1/aliplayer-min.js"></script>
		<style>
			html,
			body {
				margin: 0;
				padding: 0;
				width: 100vw;
				height: 100vh;
			}

			#player-con {
				position: fixed;
				top: 0;
				bottom: 0;
				left: 0;
				right: 0;
			}
		</style>
	</head>
	<body>
		<div class="prism-player" id="player-con"></div>
		<script>
			var playerInstance = null;
			
			const getRequest = parName => {
				var str = parName.toLowerCase() + "=";
				var gvalue = "";
				var HREF = location.href;
				var upperHREF = location.href.toLowerCase();
				if (upperHREF.indexOf(str) > 0) {
					gvalue = HREF.substring(upperHREF.indexOf(str) + str.length, upperHREF.length);
					if (gvalue.indexOf('&') > 0) gvalue = gvalue.substring(0, gvalue.indexOf('&'));
					if (gvalue.indexOf("#") > 0) gvalue = gvalue.split("#")[0];
					gvalue = decodeURIComponent(gvalue)
				}
				return gvalue;
			};
			const postMsg = (parName, event) => {
				uni.postMessage({
					data: {
						action: 'postMessage',
						act: parName,
						event: event
					}
				});
			};

			var url = getRequest("file");
			var height = getRequest("height");

		
		
			document.addEventListener('UniAppJSBridgeReady', function() {
				initPlay();
			});
			const initPlay = () => {
				playerInstance = new Aliplayer({
					"id": "player-con",
					"source": url,
					"width": "100%",
					"height": height + 'px',
					"autoplay": true,
					"isLive": false,
					"rePlay": false,
					"playsinline": true,
					"preload": true,
					"controlBarVisibility": "hover",
					"useH5Prism": true
				}, function(player) {
					playerInstance = player;
					playerInstance.on("play", function(e) {
						postMsg('play', e)
					});
					// 视频播放监听
					playerInstance.on("ready", function(e) {
						postMsg("ready", e)
					});
					// 视频暂停监听
					playerInstance.on("pause", function(e) {
						postMsg("pause", e)
					});
					playerInstance.on("startSeek", function(e) {
						postMsg("startSeek", e)
					});
					playerInstance.on("completeSeek", function(e) {
						postMsg("completeSeek", e)
					});
					// 视频播放完毕监听
					playerInstance.on("ended", function(e) {
						postMsg("ended", e)
					});
					playerInstance.on("timeupdate", function(e) {
						var cutTime = parseInt(Math.round(playerInstance.getCurrentTime()));
						postMsg("timeupdate", {
							'currentTime': cutTime
						})
					});
					console.log("The player is created");
				});
			}
			function seek(second) {
				playerInstance.seek(second)
			}
			function pause() {
				playerInstance.pause()
			}
			function play() {
				playerInstance.play()
			}
		</script>
	</body>
